<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 25306
  Date: 2025/10/11
  Time: 上午11:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <title>用户管理</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/back-index.css"/>
    <script src="${pageContext.request.contextPath}/js/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-paginator.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-mypaginator.js"></script>
    <script type="text/javascript" charset="utf-8">
        $(function () {

            $("#loginName").val("${userParam.loginName}");
            $("#nickname").val("${userParam.nickname}");
            $("#email").val("${userParam.email}");
            if("${userParam.role}" != ""){
                $("#role").val("${userParam.role}");
            }
            $("#createStartDate").val("${userParam.createStartDate}");
            $("#createEndDate").val("${userParam.createEndDate}");
            $("#loginStartDate").val("${userParam.loginStartDate}");
            $("#loginEndDate").val("${userParam.loginEndDate}");


            $(".doModify").on("click", function () {
                $(".modal-title").html("用户修改");
                $("#myModal").modal("show");
            });
            $(".updateOne").on("click", function () {
                $("#myModal").modal("hide");
            });

            // 显示隐藏查询列表
            $('#show-user-search').click(function () {
                $('#show-user-search').hide();
                $('#upp-user-search').show();
                $('.showusersearch').slideDown(500);
            });
            $('#upp-user-search').click(function () {
                $('#show-user-search').show();
                $('#upp-user-search').hide();
                $('.showusersearch').slideUp(500);
            });

            //查询提交
            $("#doSearch").click(function () {
                $("#searchForm").submit();
            })
            //分页
            $("#userPageHelper").bootstrapPaginator({
                bootstrapMajorVersion: 3,
                currentPage: "${userPage.pageNum == 0 ? 1 : userPage.pageNum}",
                totalPages: "${userPage.pages == 0 ? 1 : userPage.pages}",
                size: "normal",
                alignment: "center",
                onPageClicked: function (event, originalEvent, type, page) {
                    $("#pageNo").val(page);
                    $("#searchForm").submit();
                }
            })
            //修改显示默认值
            $(".doModify").click(function () {
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/user/findById",
                    data: {"id": $(this).attr("data-id")},
                    dataType: "json",
                    success: function (result) {
                        if (result.responseCode == "2001") {
                            // result.returnObject-->ProductType
                            $("#user_id").val(result.returnObject.id);
                            $("#username").val(result.returnObject.nickname);
                            $("#roleName").val(result.returnObject.role);
                            $("#adrees").val(result.returnObject.email);
                        } else {
                            $("#errorMsg").html(result.message);
                        }
                    }
                })
            })

            $(".updateOne").click(function () {
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/user/updateUser",
                    data: {
                        "id": $("#user_id").val(),
                        "nickname": $("#username").val(),
                        "role": $("#roleName").val(),
                        "password": $("#password").val(),
                        "email": $("#adrees").val(),
                    },
                    dataType: "json",
                    success: function (result) {
                        if (result.responseCode == "2001") {
                            location.href = "${pageContext.request.contextPath}/user/findByParams?pageNo=${userPage.pageNum == 0 ? 1 : userPage.pageNum}";
                        } else {
                            $("#errorMsg").html(result.message);
                        }
                    }
                })
            })

            $(".modifyStatus").click(function () {
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/user/updateStatus",
                    data: {"id": $(this).attr("data-id")},
                    dataType: "json",
                    success: function (result) {
                        if (result.responseCode == "2001") {
                            location.href = "${pageContext.request.contextPath}/user/findByParams?pageNo=${userPage.pageNum == 0 ? 1 : userPage.pageNum}";
                        } else {
                            $("#errorMsg").html(result.message);
                        }
                    }
                })
            })
        })
    </script>

</head>

<body>
<div class="panel panel-default" id="userInfo">
    <div class="panel-heading">
        <h3 class="panel-title">用户管理&nbsp;&nbsp;&nbsp;<span id="errorMsg" style="color: red;"></span></h3>
    </div>
    <div>
        <input type="button" value="查询" class="btn btn-success" id="doSearch" style="margin: 5px 5px 5px 15px;"/>
        <input type="button" class="btn btn-primary" id="show-user-search" value="展开搜索"/>
        <input type="button" value="收起搜索" class="btn btn-primary" id="upp-user-search" style="display: none;"/>
    </div>

    <div class="panel-body">
        <div class="showusersearch" style="display: none;">
            <form class="form-horizontal" id="searchForm" action="${pageContext.request.contextPath}/user/findByParams">
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <input type="hidden" id="pageNo" name="pageNo">
                        <label for="loginName" class="col-xs-3 control-label">登录名：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="loginName" name="loginName"
                                   placeholder="请输入登录名"/>
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label for="nickname" class="col-xs-3 control-label">昵称：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="nickname" name="nickname"
                                   placeholder="请输入昵称"/>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label for="email" class="col-xs-3 control-label">邮箱：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="email" name="email"
                                   placeholder="请输入邮箱"/>
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label for="role" class="col-xs-3 control-label">角色：</label>
                        <div class="col-xs-8">
                            <select class="form-control" id="role" name="role">
                                <option value="-1">全部</option>
                                <option value="normal">普通</option>
                                <option value="admin">管理员</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label for="createStartDate" class="col-xs-3 control-label">开始日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="createStartDate" name="createStartDate"
                                   placeholder="请输入创建开始时间:2017-10-10" pattern="\d{4}-\d{2}-\d{2}"/>
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label for="createEndDate" class="col-xs-3 control-label">结束日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="createEndDate" name="createEndDate"
                                   placeholder="请输入创建结束时间:2017-10-12" pattern="\d{4}-\d{2}-\d{2}"/>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label for="loginStartDate" class="col-xs-3 control-label">开始日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="loginStartDate" name="loginStartDate"
                                   placeholder="请输入登录开始时间:2017-10-10" pattern="\d{4}-\d{2}-\d{2}"/>
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label for="loginEndDate" class="col-xs-3 control-label">结束日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="loginEndDate" name="loginEndDate"
                                   placeholder="请输入登录结束时间:2017-10-12" pattern="\d{4}-\d{2}-\d{2}"/>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="show-list">
            <table class="table table-bordered table-hover"
                   style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">编号</th>
                    <th class="text-center">登录名</th>
                    <th class="text-center">角色</th>
                    <th class="text-center">昵称</th>
                    <th class="text-center">邮箱</th>
                    <th class="text-center">创建日期</th>
                    <th class="text-center">最近登录日期</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                <c:forEach items="${userPage.list}" var="user">
                    <tr>
                        <td>${user.id}</td>
                        <td>${user.loginName}</td>
                        <td>${user.role}</td>
                        <td>${user.nickname}</td>
                        <td>${user.email}</td>
                        <td>${user.createDate}</td>
                        <td>${user.loginDate}</td>
                        <td class="text-center">
                            <input type="button" class="btn btn-warning btn-sm doModify" data-id="${user.id}"
                                   value="修改"/>
                            <c:if test="${user.status== 1}">
                                <input type="button" class="btn btn-danger btn-sm modifyStatus" data-id="${user.id}"
                                       data-status="${user.status}" value="禁用"/>
                            </c:if>
                            <c:if test="${user.status== 0}">
                                <input type="button" style="background-color: #5cb85c;border-color: #5cb85c"
                                       class="btn btn-danger btn-sm modifyStatus" data-id="${user.id}"
                                       data-status="${user.status}" value="启用"/>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <ul id="userPageHelper"></ul>
        </div>
        <!-- 分页 -->
        <div style="text-align: center;">
            <ul id="myPages"></ul>
        </div>

        <div class="modal fade" tabindex="-1" id="myModal">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">用户修改</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label for="user_id" class="col-xs-4 control-label">编号：</label>
                            <div class="col-xs-4">
                                <input type="text" class="form-control" id="user_id" readonly/>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="username" class="col-xs-4 control-label">昵称：</label>
                            <div class="col-xs-4">
                                <input type="text" class="form-control" id="username"/>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="roleName" class="col-xs-4 control-label">角色：</label>
                            <div class="col-xs-4">
                                <input type="text" class="form-control" id="roleName"/>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="password" class="col-xs-4 control-label">密码：</label>
                            <div class="col-xs-4">
                                <input type="text" class="form-control" id="password"/>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="email" class="col-xs-4 control-label">邮箱：</label>
                            <div class="col-xs-4">
                                <input type="email" class="form-control" id="adrees"/>
                            </div>
                        </div>
                        <br>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-warning updateOne">修改</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>
